import argparse
import logging
import pandas
import sys
import time
from job import Worker

logging.basicConfig(
    stream=sys.stdout, level=logging.INFO, format='%(asctime)s-%(levelname)s-%(message)s'
)


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--depth", type=int, default=4)
    parser.add_argument("--directory", type=str, default="/pdfs/future")
    parser.add_argument("--beg", type=str, default="2024-01-01")
    parser.add_argument("--end", type=str, default="2024-07-30")
    params, _ = parser.parse_known_args()
    temp_dt = pandas.to_datetime(params.end)
    last_dt = pandas.to_datetime(params.beg)
    hour_lt = ["00", "01", "02", "09", "10", "11", "13", "14", "15", "21", "22", "23"]
    while temp_dt > last_dt:
        for hour in hour_lt[::-1]:
            for minute in (45, 30, 15, 00):
                temp_dt = pandas.to_datetime(f"{temp_dt.strftime('%Y-%m-%d')} {hour}:{minute}")
                logging.info(temp_dt)
                Worker(params.depth, params.directory, temp_dt).start()
                time.sleep(1)


if __name__ == "__main__":
    main()
